package com.dream.wukong.common.core.jdbc.dialect;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.util.Map;

/**
 * @Author: wuyichao
 * @Description:
 * @Date: Created in 10:09 2018/9/18.
 * @Modified:
 */
public abstract class Dialect {

    public static String ROWS_COUNT = "ROWS_COUNT" ;

    public static String OFFSET = "OFFSET" ;

    public static String LIMIT = "LIMIT" ;


    protected Log log = LogFactory.getLog(getClass());

    public abstract String getPageSql(String sql, int offset, int limit ,Map<String, Object> map);

    public String getCountString(String sql )
    {
        StringBuffer countSelect = new StringBuffer(sql.length() + 100);
        countSelect.append("select count(1) "+ROWS_COUNT+" from ( ");
        countSelect.append(sql);
        countSelect.append(" ) a  ");
        return countSelect.toString();
    }

    public boolean isNumber(String dbType){
        return StringUtils.contains(dbType, "INT")||StringUtils.contains(dbType, "NUMBER") ;
    }

    public boolean isDate(String dbType){
        return StringUtils.contains(dbType, "DATE")||StringUtils.contains(dbType, "TIME") ;
    }


}